package com.zc.auth.security.core.configuration;

import com.zc.auth.security.core.configuration.adapter.WebFluxSecurityConfigureAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;

/**
 * @author zcj
 * @version 1.0.0
 * @date 2022/1/13 15:01
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
@ConditionalOnMissingBean(value = {SecurityWebFilterChain.class})
@AutoConfigureAfter({WebFluxSecurityConfiguration.class})
@EnableWebFluxSecurity
//@EnableReactiveMethodSecurity
public class WebFluxFilterChainConfiguration {

    @Autowired
    private WebFluxSecurityConfigureAdapter webFluxSecurityConfigureAdapter;

    @Bean
    public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
        return this.webFluxSecurityConfigureAdapter.webfluxWebFilterChain(http);
    }
}
